﻿using FTBS.Models.DAO;
using FTBS.Models.Entities;
using FTBS.Models.Entities.Concert;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FTBS.Models.BLO
{
    public class TheaterBLO
    {
        private TheaterDAO _theaterDao = new TheaterDAO();
        private UserDAO _userDao = new UserDAO();
        //private SettingTheaterDAO _settingTheaterDao = new SettingTheaterDAO();

        /// <summary>
        /// Get All Information Of Theater
        /// </summary>
        /// <returns>List of Theater</returns>
        /// <author>VuongVT</author>
        public List<Theater> GetAllTheaterInfo()
        {
            return _theaterDao.GetAllTheaterInfo();
        }

        /// <summary>
        /// Get All Information Of Theater to create price ticket
        /// </summary>
        /// <returns>List of Theater</returns>
        /// <author>HungPH</author>
        public List<Theater> GetAllTheaterInfoToCreatePriceTicket()
        {
            return _theaterDao.GetAllTheaterInfoToCreatePriceTicket();
        }

        /// <summary>
        /// Get all theaters have film in Schedule
        /// </summary>
        /// <returns>List of Theater</returns>
        public List<Theater> GetAllTheatersInSchedule()
        {
            return _theaterDao.GetAllTheatersInSchedule();
        }

         /// <summary>
        /// Get Theater by Id
        /// </summary>
        /// <param name="theaterId"></param>
        /// <returns></returns>
        public Theater GetTheaterById(int theaterId)
        {
            return _theaterDao.GetTheaterById(theaterId);
        }

        /// <summary>
        /// Check exist TheaterName
        /// </summary>
        /// <param name="theater"></param>
        /// <returns>true: Exist TheaterName -- false: Not Exist TheaterName</returns>
        public bool IsExistTheater(Theater theater)
        {
            return _theaterDao.IsExistTheater(theater);
        }

        /// <summary>
        /// Check Exist Theater when Update a theater
        /// </summary>
        /// <param name="theater"></param>
        /// <returns>true: Exist TheaterName -- false: Not Exist TheaterName</returns>
        /// <author>VuongVT</author>
        public bool IsExistTheaterUpdate(Theater theater)
        {
            return _theaterDao.IsExistTheaterUpdate(theater);
        }

        /// <summary>
        /// Create a new Theater
        /// </summary>
        /// <param name="theater"></param>
        /// <returns>1: success -- 0: fail</returns>
        public int CreateTheater(Theater theater)
        {
            return _theaterDao.CreateTheater(theater);
        }

        /// <summary>
        /// Edit a Theater
        /// </summary>
        /// <param name="theater"></param>
        /// <returns>1: Success --- 0: Fail</returns>
        public int EditTheater(Theater theater)
        {
            return _theaterDao.EditTheater(theater);
        }       

        /// <summary>
        /// Delete a Theater
        /// </summary>
        /// <param name="theater"></param>
        /// <returns>1: Success --- 0: Fail</returns>
        public int DeleteTheater(Theater theater)
        {
            return _theaterDao.DeleteTheater(theater);
        }

        /// <summary>
        /// Get All Supplier
        /// </summary>
        /// <returns>List of Supplier</returns>
        public IEnumerable<User> GetAllSupplier()
        {
            return _userDao.GetAllSupplier();
        }

        /// <summary>
        /// Check the TheaterId is used in Theater and doesn't have Booked ticket or not
        /// This function is used for user Click to Edit in List Theater
        /// </summary>
        /// <param name="showTimeId"></param>
        /// <returns>True: Is Exist ---- False: Not Exist</returns>
        /// <author>VuongVT</author>
        public bool IsTheaterUsedInScheduleAndBooked(int roomId)
        {
            return _theaterDao.IsTheaterUsedInScheduleAndBooked(roomId);
        }

        /// <summary>
        /// Check the TheaterId is used in Schedule or not
        /// This function is used for user Click to Delete in List Theater
        /// </summary>
        /// <param name="showTimeId"></param>
        /// <returns>True: Is Exist ---- False: Not Exist</returns>
        /// <author>VuongVT</author>
        public bool IsTheaterUsedForSchedule(int roomId)
        {
            return _theaterDao.IsTheaterUsedForSchedule(roomId);
        }

        /// <summary>
        /// Get theaters of a supplier
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<Theater> GetTheatersBySupplier(string id)
        {
            List<Theater> listTheater = new List<Theater>();
            listTheater = _theaterDao.GetTheatersBySupplierName(id);
            return listTheater;
        }

        /// <summary>
        /// Check is Theater Validate or not
        /// </summary>
        /// <param name="theater"></param>
        /// <returns>True: Valid -- False: Not valid</returns>
        public bool IsValidTheater(Theater theater)
        {
            if (theater.TheaterName == null || string.Empty.Equals(theater.TheaterName))
            {
                return false;
            }
            if (theater.Address == null || string.Empty.Equals(theater.Address))
            {
                return false;
            }
            if (theater.PhoneNumber == null || string.Empty.Equals(theater.PhoneNumber))
            {
                return false;
            }
            if (theater.UserName == null || string.Empty.Equals(theater.UserName))
            {
                return false;
            }
            if (theater.Latitude == null || string.Empty.Equals(theater.Latitude))
            {
                return false;
            }
            if (theater.Longitude == null || string.Empty.Equals(theater.Longitude))
            {
                return false;
            }
            if (theater.ImageURL == null || string.Empty.Equals(theater.ImageURL))
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Validate value of setting of theater
        /// </summary>
        /// <param name="settingOfTheater"></param>
        /// <returns></returns>
        public bool IsValidSetting(Theater settingOfTheater)
        {
            if (settingOfTheater.MaxChairInRow > 20)
            {
                return false;
            }
            if (settingOfTheater.MaxColumnInRoom > 20)
            {
                return false;
            }
            if (settingOfTheater.MaxBookingTicket > 10 || settingOfTheater.MaxBookingTicket <= 0)
            {
                return false;
            }
            if (settingOfTheater.DeadlineCreateTicket == 0)
            {
                return false;
            }
            if (settingOfTheater.PointWithMoney == 0)
            {
                return false;
            }
            if (settingOfTheater.TimeForBooking == 0)
            {
                return false;
            }
            if (settingOfTheater.DeadlineForBooking < 60)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Add new theater and theater's setting
        /// </summary>
        /// <param name="theaterAndSettingEnt"></param>
        /// <author>VuongVT</author>
        public int AddNewTheaterAndSetting(SettingTheaterConcertEntity theaterAndSettingEnt)
        {
            return _theaterDao.AddNewTheaterAndSetting(theaterAndSettingEnt);
        }

        /// <summary>
        /// get all theaters by username of supplier
        /// </summary>
        /// <param name="username"></param>
        /// <returns>list of theaters</returns>
        /// <author>hungph</author>
        public List<Theater> GetAllTheatersByUsernameOfSupplier(string username)
        {
            return _theaterDao.GetAllTheatersByUsernameOfSupplier(username);
        }
    }
}